// highcharts contextmenu{{{
(function(Highcharts){
	if(!Highcharts) return false;
	Highcharts.wrap(Highcharts.Chart.prototype, 'firstRender', function(proceed){
		proceed.call(this);
		if(!this.container) return false;
		var chart = this,
			container = this.container,
			plotLeft = this.plotLeft,
			plotTop = this.plotTop,
			plotWidth = this.plotWidth,
			plotHeight = this.plotHeight,
			inverted = this.inverted,
			pointer = this.pointer;
		container.oncontextmenu = function(e){
			var hoverPoint = chart.hoverPoint, chartPosition = pointer.chartPosition;
			this.rightClick = true;
			e = pointer.normalize(e);
			e.cancelBubble = true;
			e.returnValue = false;
			if(e.stopPropagation){
				e.stopPropagation();
			}
			if(e.preventDefault){
				e.preventDefault();
			}
			if(!pointer.hasDragged){
				if(hoverPoint && pointer.inClass(e.target, 'highcharts-tracker')){
					var plotX = hoverPoint.plotX, plotY = hoverPoint.plotY;
					Highcharts.extend(hoverPoint, {
						pageX: chartPosition.left + plotLeft + (inverted ? plotWidth - plotY : plotX),
						pageY: chartPosition.top + plotTop + (inverted ? plotHeight - plotX : plotY)
					});
					HighchartsAdapter.fireEvent(
						hoverPoint.series, 'contextmenu',
						Highcharts.extend(e, {point: hoverPoint})
					);
					hoverPoint.firePointEvent('contextmenu', e);
				}
			}
		};
	});
}(global.Highcharts));
// }}}
// vim: fdm=marker
